/**
 * Created by yanghaibo
 */
var orderDetailParam = {};
(function(doc, win) {
    // sui 页面就绪时间
    $(doc).on("pageInit", "#orderDetailPage", function() {
        debugger
        orderDetailParam = {}; // 清空参数
        var orderId = CommonUtil.getUrlParam("orderId");
        var orderType = CommonUtil.getUrlParam("orderType");
        var newOrderStatus  = CommonUtil.getUrlParam("orderStatus");
        if (!orderId) {
            DialogUtil.dialogWarn("无效订单");
            return;
        }
        orderDetailParam.orderId = orderId;
        orderDetailParam.orderType = orderType;
        var controller = new OrderDetailController();
        controller.getOrderDetail(orderId,orderType,newOrderStatus);
    });

    //默认订单退款详情展开
    $(document).on("click", "#orderDetailPage .section .title", function () {
            var $this = $(this);
            if ($this.find(".zhk-list_rarrow").length) {
                $this.toggleClass("fold");
            }
        })
    //监听返回是否是退款返回
        $(document).on("click", "#orderDetailPage .header .back" , function () {
            var flag = CommonUtil.getUrlParam("flag");
            if(flag){
                $.router.load("order.html");
            }else{
                window.history.back(-1); 
            }
        })

        //监听退款
        $(document).on("keyup","#xmg_shrje",function(){
            var inputPwd = $("#xmg_dlpass").val();
            var tkMoney = $("#xmg_hqddje").html();
            tkMoney = tkMoney.replace(' ¥ ','');
            tkMoney = parseFloat(tkMoney);
           var srMoney = $(this).val();
           srMoney = parseFloat(srMoney);
            if(srMoney>tkMoney){
                DialogUtil.dialogWarn("输入金额不能大于应收金额");
                $(this).val("");
            } 
            if(srMoney<=tkMoney && inputPwd.length>5 && srMoney!=0){
                $("#xmg_refunds").removeClass("disable");
            }else{
                $("#xmg_refunds").addClass("disable");
            }
            
        })
         //监听密码
         $(document).on("input","#xmg_dlpass",function(){
            var srMoney = $("#xmg_shrje").val();
           var srPass = $(this).val();
            if(srPass.length>5 && srPass.length<15 && srMoney != ''&& srMoney!=0){
                $("#xmg_refunds").removeClass("disable");
            }else{
                $("#xmg_refunds").addClass("disable");
            }
        })
        //点击确定退款
        $(document).on("click", "#orderDetailPage .refund-dialog .btn-box .right", function () {
            var orderId = CommonUtil.getUrlParam("orderId");
            var shopId = CommonUtil.getUrlParam("shopId");
            var orderType = CommonUtil.getUrlParam("orderType");
            var newOrderStatus  = CommonUtil.getUrlParam("orderStatus");
            var refundMoney = $("#xmg_shrje").val();//获取退款输入金额
            var refundReason = $("#xmg_sryy").val();//获取输入的退款原因
            var inputPwd = $("#xmg_dlpass").val();//获取输入的登录密码验证
            
            if((refundMoney == '' || refundMoney == 0) || (inputPwd.length<6 || inputPwd.length>15)){
                return;
            }
        
           orderFilterParam.params.payType = "";
           orderFilterParam.params.orderStatus = "";
           orderFilterParam.params.orderSource = "";
           orderFilterParam.params.shopId = "";
           orderFilterParam.params.shopName = "";
            var controller = new OrderDetailController();
            controller.getOrderDetailRefund(orderId,shopId,refundMoney,refundReason,inputPwd,orderType,newOrderStatus);
            $(".refund-dialog").addClass('hide');
            $(".page-body").removeClass("no-scroll");
            $("#xmg_shrje").val("");
            $("#xmg_sryy").val("");
            $("#xmg_dlpass").val("");
            $("#xmg_refunds").addClass("disable");
        });


        //显示退款弹窗
        $(document).on("click", "#orderDetailPage .header .right .rightTk", function () {
            var tkMoney= $("#xmg_hqddje").html();//获取退款金额
            $("#xmg_tkje").html(tkMoney);//放入退款金额
            var skWay = $("#xmg_hqskfs").html();//获取支付方式
            $("#xmg_tkfs").html(skWay);//赋值到退款方式上
            $(".refund-dialog").removeClass('hide');
            $(".page-body").addClass("no-scroll");
        });
        //关闭退款弹窗
        $(document).on("click", "#orderDetailPage .refund-dialog .btn-box .left", function () {
            $(".refund-dialog").addClass('hide');
            $(".page-body").removeClass("no-scroll");
            $("#xmg_shrje").val("");
            $("#xmg_sryy").val("");
            $("#xmg_dlpass").val("");
            $("#xmg_refunds").addClass("disable");
        });

})(document, window);

